package com.data;

import org.json.JSONObject;

import com.constant.Constant;
import com.net.AsyncRequest;
import com.net.ClientException;
import com.net.RequestParameter;

/**
 * 启动时请求，
 * 返回当前会话id号和是否有更新消息
 * 请求参数
 * <version>当前版本号
 * @author mjh
 *
 */
public final class StartData extends BaseData {

	private long mId;
	private String mUrl;
	private String mVersion;
	private String mDesc;
	
	@Override
	public void startParse(RequestParameter parameter) throws Exception,
			ClientException {
		String rs = AsyncRequest.openUrl(Constant.SERVER_URL + "/start", AsyncRequest.HTTP_GET, parameter);
		if(rs == null)
			return;
		
		JSONObject json = new JSONObject(rs);
		if(json.isNull("id"))
		return;
		
		mId = json.getLong("id");
		if(json.isNull("update"))
			return;
		
		json = json.getJSONObject("update");
		mUrl = json.getString("url");
		mVersion = json.getString("version");
		mDesc = json.getString("desc");
	}
	
	public long getId() {
		return this.mId;
	}
	
	public String getUrl() {
		return this.mUrl;
	}
	
	public String getDesc() {
		return this.mDesc;
	}
	
	public String getVersion() {
		return this.mVersion;
	}
	
	public void printData() {
		System.out.println(mId);
		/*System.out.println(mDesc);
		System.out.println(mVersion);
		System.out.println(mUrl);*/
	}
}
